﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YasharEl.Infrastructure.Core.EntityModel.Prototype
{
    public abstract class AbstractDataTypeValueConverter : IDataTypeValueConverter
    {
        #region IDataTypeValueConverter Members

        public virtual bool IsValid(object value)
        {
            if (!HasValue(@value))
                return false;

            try
            {
                object unwrappedValue = UnwrapRealValue(@value);
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region Abstract Methods

        public abstract object UnwrapRealValue(object value);

        public abstract string WrapValue(object value);

        public abstract bool HasValue(object value);

        #endregion
    }
}
